package model;

import java.io.Serializable;
import java.util.ArrayList;

public class Conversation implements Serializable {

    private String conversationID;
    private ArrayList<Message> conversationMessages;
    private ArrayList<User> conversationUsersActive;
    private ArrayList<User> conversationAllUsers;
    private String conversationDateStart;
    private String conversationDateEnd;

    public Conversation() {
        conversationMessages = new ArrayList<>();
        conversationUsersActive = new ArrayList<>();
        conversationAllUsers = new ArrayList<>();
    }

    public Conversation(String id, ArrayList<Message> messages, ArrayList<User> listOfUsersActive,
            ArrayList<User> listOfAllUsers, String dateStart, String dateEnd) {
        conversationID = id;
        conversationMessages = messages;
        conversationUsersActive = listOfUsersActive;
        conversationAllUsers = listOfAllUsers;
        conversationDateStart = dateStart;
        conversationDateEnd = dateEnd;
    }

    public String getConversationID() {
        return this.conversationID;
    }

    public void setConversationID(String id) {
        this.conversationID = id;
    }

    public ArrayList<Message> getConversationMessages() {
        return this.conversationMessages;
    }

    public void setConversationMessages(ArrayList<Message> conversation) {
        this.conversationMessages = conversation;
    }

    public ArrayList<User> getConversationAllUsers() {
        return conversationAllUsers;
    }

    public void setConversationAllUsers(ArrayList<User> conversationAllUsers) {
        this.conversationAllUsers = conversationAllUsers;
    }

    public ArrayList<User> getConversationUsersActive() {
        return conversationUsersActive;
    }

    public void setConversationUsersActive(ArrayList<User> conversationUsersActive) {
        this.conversationUsersActive = conversationUsersActive;
    }

    public String getConversationDateStart() {
        return this.conversationDateStart;
    }

    public void setConversationDateStart(String dateStart) {
        this.conversationDateStart = dateStart;
    }

    public String getConversationDateEnd() {
        return this.conversationDateEnd;
    }

    public void setConversationDateEnd(String dateEnd) {
        this.conversationDateEnd = dateEnd;
    }

    public String generateConversationID() {
        String id;
        id = java.util.UUID.randomUUID().toString().substring(0, 29);
        return id;
    }

    public Boolean addUserAtConversation(User newUser) {
        Boolean correct;
        if (this.getConversationUsersActive().contains(newUser)) {
            correct = false;
        } else {
            correct = this.getConversationUsersActive().add(newUser);
            if (!this.getConversationAllUsers().contains(newUser)) {
                this.getConversationAllUsers().add(newUser);
            }
        }
        return correct;
    }

    public Boolean removeUserAtConversation(User user) {
        Boolean correct = false;
        if (this.getConversationUsersActive().contains(user)) {
            correct = this.getConversationUsersActive().remove(user);
        }
        return correct;
    }

    public Boolean addMessageAtConversation(Message message) {
        Boolean correct = false;
        this.conversationMessages.add(message);
        if (this.getConversationMessages().contains(message)) {
            correct = true;
        }
        return correct;
    }
}
